/*
 * Copyright (C) 2009 Leandro de Oliveira Aparecido <lehphyro@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.japa.repository;

import java.lang.annotation.*;
import java.util.*;

/**
 * Common parameters to interact with the repository.
 * <p>Usually, defined using annotations.
 * 
 * @author Leandro Aparecido
 * @since 1.0
 * @see com.google.code.japa.annotation.RepositoryQuery
 * @see com.google.code.japa.annotation.RepositoryReturn
 * @see com.google.code.japa.repository.query.RepositoryQueryParameters
 * @see com.google.code.japa.repository.ret.RepositoryReturnParameters
 */
public class RepositoryAnnotationParameters {
	/**
	 * Name of the query to execute to load the repository values.
	 */
	private String queryName;
	
	/**
	 * Parameters to be passed to the query mapped as name => parameter.
	 */
	private Map<String, QueryParameter> parameters;
	
	/**
	 * Type of the target of the repository value.
	 */
	private ElementType targetType;
	
	public RepositoryAnnotationParameters() {
		parameters = new HashMap<String, QueryParameter>();
	}

	public String getQueryName() {
		return queryName;
	}

	public void setQueryName(String queryName) {
		this.queryName = queryName;
	}

	public Map<String, QueryParameter> getParameters() {
		return parameters;
	}

	public void setParameters(Map<String, QueryParameter> parameters) {
		this.parameters = parameters;
	}

	public ElementType getTargetType() {
		return targetType;
	}

	public void setTargetType(ElementType targetType) {
		this.targetType = targetType;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((parameters == null) ? 0 : parameters.hashCode());
		result = prime * result + ((queryName == null) ? 0 : queryName.hashCode());
		result = prime * result + ((targetType == null) ? 0 : targetType.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		RepositoryAnnotationParameters other = (RepositoryAnnotationParameters) obj;
		if (parameters == null) {
			if (other.parameters != null) {
				return false;
			}
		} else if (!parameters.equals(other.parameters)) {
			return false;
		}
		if (queryName == null) {
			if (other.queryName != null) {
				return false;
			}
		} else if (!queryName.equals(other.queryName)) {
			return false;
		}
		if (targetType == null) {
			if (other.targetType != null) {
				return false;
			}
		} else if (!targetType.equals(other.targetType)) {
			return false;
		}
		return true;
	}
	
	@Override
	public String toString() {
		return "name=" + queryName;
	}
}
